# -*- coding: utf-8 -*-
# flake8: noqa

from qiniu import Auth, put_file, etag, urlsafe_base64_encode
import qiniu.config
from qiniu.compat import is_py2, is_py3


"""
    配置信息
"""

# 需要填写你的 Access Key 和 Secret Key
access_key = 'u7ifJJ5fEl-25VxsjxCl-b-HO5OWQQ6u8fZEeTXN'
secret_key = 'PSk2Y_9NNL2uXruSIvU9NWoKfgZUrl1LhrtAhfHc'

# 要上传文件的本地路径
localfile = 'OIP-C.jpg'

# 上传到七牛后保存的文件名
key = 'my-python-七牛.png'

# 要上传的空间
bucket_name = 'aiarta'

"""
    上传
"""

# 构建鉴权对象
q = Auth(access_key, secret_key)


# 生成上传 Token，可以指定过期时间等
token = q.upload_token(bucket_name, key, 3600)

ret, info = put_file(token, key, localfile)
print(ret)
print(info)

"""
{'hash': 'FlXo9XPWp3wV2sTeww87V0eq4b0C', 'key': 'my-python-七牛.png'}
_ResponseInfo__response:<Response [200]>, exception:None, status_code:200, text_body:{"hash":"FlXo9XPWp3wV2sTeww87V0eq4b0C","key":"my-python-七牛.png"}, req_id:VbYAAACAjSWYApAW, x_log:X-Log
"""

if is_py2:
    assert ret['key'].encode('utf-8') == key
elif is_py3:
    assert ret['key'] == key

assert ret['hash'] == etag(localfile)
